const AC_GAME_OBJECTS = [];

export class ACGameObject{
    constructor(){
        AC_GAME_OBJECTS.push(this);
        this.timedelta = 0;
        this.has_called_start = false;
    }
    //第一帧
    start(){

    }
    //每一帧执行一次
    update(){

    }
    destroy(){
        for(let i in AC_GAME_OBJECTS){
            const obj = AC_GAME_OBJECTS[I];
            if(obj == this){
                AC_GAME_OBJECTS.splice(i);
                break;
            }
        }
    }

}


let last_timestamp; //


const step = timestamp =>{
    for(let obj of AC_GAME_OBJECTS){
        if(!obj.has_called_start){
            obj.has_called_start = true;
            obj.start();
        }else{
            obj.timedelta = timestamp - last_timestamp; 
            obj.update();
        }
    }
    list_timestamp = timestamp;
    requestAnimationFrame(step)
}

requestAnimationFrame(step)